import { defineConfig } from 'vite'
import { createVuePlugin } from 'vite-plugin-vue2'
import RollupPluginAutoRouter from 'rollup-plugin-auto-router'

export default ({ mode }) => {
  const _plugins =
    mode !== 'development'
      ? [createVuePlugin(/* options */)]
      : [createVuePlugin(/* options */), RollupPluginAutoRouter()]

  return defineConfig({
    plugins: _plugins,
    base: './',
    server: {
      open: true,
      port: 9001,
      host: '0.0.0.0',
      proxy: {
        '/dev': {
          target: 'https://ws-uat-gateway.hzguode.com',
          ws: true,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/dev/, ''),
        },
        '/cloudcall-business-api': {
          target: 'http://10.1.6.88:8087',
          // target: 'http://10.1.8.114:8087',
          ws: true,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/cloudcall-business-api/, ''),
        },
        '/cloudcall-media-api': {
          // target: 'http://10.1.8.114:8085',
          target: 'http://10.1.6.88:8085',
          ws: true,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/cloudcall-media-api/, ''),
        },
      },
    },
    resolve: {
      alias: {
        '@': '/src',
      },
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: '@import \'@/assets/styles/variables.scss\';',
        },
      },
    },
  })
}
